package com.qys.livesMall.finance.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qys.livesMall.common.constants.Constants;
import com.qys.livesMall.finance.dao.FinanceUserAccountDao;
import com.qys.livesMall.finance.mapper.FinanceUserAccountMapper;
import com.qys.livesMall.finance.model.entity.user.FinanceUserAccount;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 店铺余额表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-06-06
 */
@Service
public class FinanceUserAccountDaoImpl extends ServiceImpl<FinanceUserAccountMapper, FinanceUserAccount> implements FinanceUserAccountDao {

    @Override
    public FinanceUserAccount getByUserId(Long userId) {
        LambdaQueryWrapper<FinanceUserAccount> qw=new LambdaQueryWrapper<>();
        qw.eq(FinanceUserAccount::getUserId,userId);
        qw.eq(FinanceUserAccount::getDeleted, Constants.YesNo.NO);
        qw.last("limit 1");
        return getOne(qw);
    }

    @Override
    public List<FinanceUserAccount> getByUserIds(List<Long> userIds) {
        LambdaQueryWrapper<FinanceUserAccount> qw=new LambdaQueryWrapper<>();
        qw.in(CollectionUtils.isNotEmpty(userIds),FinanceUserAccount::getUserId,userIds);
        qw.eq(FinanceUserAccount::getDeleted, Constants.YesNo.NO);
        return list(qw);
    }

    @Override
    public FinanceUserAccount getByShopId(Long shopId) {
        LambdaQueryWrapper<FinanceUserAccount> qw=new LambdaQueryWrapper<>();
        qw.eq(FinanceUserAccount::getDeleted, Constants.YesNo.NO);
        qw.last("limit 1");
        return getOne(qw);
    }

    @Override
    public List<FinanceUserAccount> liatByShopIds(List<Long> shopIds) {
        LambdaQueryWrapper<FinanceUserAccount> qw=new LambdaQueryWrapper<>();
        qw.eq(FinanceUserAccount::getDeleted, Constants.YesNo.NO);
        return list(qw);
    }

    @Override
    public BigDecimal getTotalBalance(Integer userSysType) {
        return baseMapper.getTotalBalance(userSysType);
    }


}
